<!DOCTYPE html>
<html lang="zh">
<head>
	<title>接口列表</title>
	<script src="${res}/js/jquery-1.9.1.min.js"></script>
	<script src="${res}/interface/code-formatter.js" type="text/javascript"></script>
	<link href="${res}/interface/code-formatter.css" type="text/css" rel="stylesheet"></link>
<style>
#rawJson {
width:100%; height: 50px;
}
</style>
<script>
function invoke(){
	$.ajax({
	    url: '${base}/directive.json',
	    type: 'GET',
	    data:$('#dataForm').serialize(),
	    contentType:'application/json; charset=UTF-8',
	    dataType: 'text',
	    success: function (data) {
	    	$('#rawJson').val(data);
	    	process($('#rawJson'),$('.canvas'));
	    }
	});
}
function use(action){
	$('input[name=action]').val(action);
	$.ajax({
		url:'${base}/directive.json?action='+action+'&showParamters=true',type: 'GET',
		contentType:'application/json; charset=UTF-8',
		dataType: 'json',
		success: function (data) {
			$('#paramter').empty();
			$(data.parameters).each(function(index,paramter){
				var value = null===paramter.defaultValue?'':paramter.defaultValue;
				$('#paramter').append('<lable>&'+paramter.name+'=</lable><input type="text" name="'+paramter.name+'" size="10" value="'+value+'"/>');
			});
		}
	});
	return false;
}
$.ajax({
	url:'${base}/directives.json',type: 'GET',
	contentType:'application/json; charset=UTF-8',
	dataType: 'json',
	success: function (dataList) {
		$(dataList).each(function(index,data){
			$('#interfaes').append(' <a href="javascript:;" onclick="return use(\''+data+'\');">'+data+'</a> ');
		});
	}
});
</script>
</head>
<body>
	<fieldset>
		<legend>接口测试</legend>
	  	<p>
	  		<form id="dataForm">地址：${base}/directive.json?action=<input name="action" size="10"/><span id="paramter"></span></form>
	  	</p>
		<p><input type="button" value="发送请求" onclick="invoke()"/></p>
		<p id="interfaes">接口列表：</p>
	</fieldset>
	<fieldset>
		<legend>返回报文</legend>
		<textarea id="rawJson"></textarea>
		<p><input type="button" value="格式化" onclick="process($('#rawJson'),$('.canvas'))"/></p>
		<div class="canvas"></div>
	</fieldset>
</body>
</html>